begintownscript;

variables;
short choice;

body;

beginstate 0; //INIT_STATE
	add_range_to_group(6,10,1); //Loyalists downstairs
	
	//if the archers have been spared, erase them
	if(get_flag(4,1) == 1) {
		erase_char(11);
		erase_char(12);
		}
	
	//weaken the two up here
	add_range_to_group(11,12,2); //terrified archers
	set_level(1002,5); //terrified guy is a pushover

	if(get_flag(4,0) == 0) {
		reset_dialog();
		add_dialog_str(0,"You reach the top of the stairs and find two Darkside Loyalists cowering against the windows. They don't move to attack.",0);
		add_dialog_str(1,"Quickly glancing around the room, you also notice a large cauldron, and that the air smells like lantern oil.",0);
		run_dialog(1);
		set_flag(4,0,1);
		}
break;

beginstate 1; //EXIT_STATE
break;

beginstate 2; //START_STATE
	//Checking for the lead pc each turn... not necessary here
	//pc_counter = 0;
	//while(char_ok(pc_counter) == 0) {
	//	pc_counter = pc_counter + 1;
	//	}
	//lead_char = pc_counter;
	
	//checking to see if the Loyalists are still alive
	if((num_chars_in_group(1) == 0) && (get_flag(3,1) == 0)) {
		reset_dialog();
		add_dialog_str(0,"As the you deal the final blow to the last of the Loyalists outside, he clutches his chest and utters three words: _Dorikas will prevail._",0);
		if(get_flag(4,1) >= 1)
			add_dialog_str(1,"In spite of the ominous last words, you breathe a sigh of relief. With all of the Loyalists taken care of, maybe you can figure out a way to distract the ships to the south...",0);
		run_dialog(1);
		set_flag(3,1,1);
		}
	
	if((num_chars_in_group(2) == 0) && (get_flag(4,1) != 1) && (get_flag(4,1) != 2)) {
		if(get_flag(3,1) == 1)
			message_dialog("With the last of the Loyalists dead, you have some time to look around. Maybe you can figure out a way to distract the ships to the south...","");
		set_flag(4,1,2);
		}
	
break;

beginstate 10; //stairs down
	block_entry(1);
	reset_dialog();
	add_dialog_str(0,"There are some stairs here, leading down.",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Climb the stairs.");
	choice = run_dialog(1);
	if(choice == 2) {
		if(is_combat() == 1) {
			print_str_color("Not while in combat mode.",1);
			end();
			}
		move_to_new_town(3,19,23);
		}
break;

beginstate 20; //pot of oil
	if(get_flag(4,2) > 0)
		end();

	//if the Loyalists are still there, end
	else if(get_flag(4,1) == 0) {
		message_dialog("You turn to look at the cauldron, but remember that the Loyalists are still in the room. You should probably deal with them first.","");
		end();
		}

	reset_dialog();
	add_dialog_str(0,"Just as you suspected, this appears to be a cauldron of lantern oil. You stare at it for a while, and a plan slowly forms in your mind...",0);
	add_dialog_str(1,"The Loyalists clearly captured this watchtower for a reason. They would probably come running if it was on fire, and you have the means to make that happen.",0);
	add_dialog_str(2,"What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Tip over the cauldron.");
	choice = run_dialog(1);
	if(choice == 2) {
		reset_dialog();
		add_dialog_str(0,"You tip the cauldron over, emptying the highly-flammable oil onto the ground. Now all you need is to get far away and light it.",0);
		add_dialog_str(1,"...without somehow lighting it accidentally. You catch your breath as you remember that the braziers are (thankfully) unlit.",0);
		run_dialog(1);
		set_flag(4,2,1);
		set_terrain(20,25,248);
		}
break;